<!DOCTYPE html>
<div style="height: 1000px"></div>
<a id="a" href="#bottom">Link to bottom</a>
<div style="height: 1000px"></div>
<a name="bottom"></a>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/js-test-resources/gesture-util.js"></script>
<script>

var a = document.getElementById("a");
var source = GestureSourceType.MOUSE_INPUT;
var haveSeenHashChange =  false;
var asyncTest = async_test("Scroll position restored from history navigation to same document");

window.onhashchange = function() {
    if (!haveSeenHashChange) {
        haveSeenHashChange = true;
        asyncTest.step(function() {
            assert_greater_than(window.scrollY, 800);
        });
        history.back();
    } else {
        asyncTest.step(function() {
            assert_equals(window.scrollY, 800);
        });
        asyncTest.done();
    }
}

window.onload = async () => {
    await smoothScroll(800, 0, 0, source, 'down', SPEED_INSTANT);
    await waitFor( () => {
        return window.scrollY == 800;
    });

    var x = a.getBoundingClientRect().left + 2;
    var y = a.getBoundingClientRect().top + 2;
    await mouseClickOn(x, y);
}
</script>
